//
//  STDSLog.h
//  STDSRenderSDKIOS
//
//  Created by 陈学明 on 2023/5/11.
//

#ifndef STDSLog_h
#define STDSLog_h
#include <stdio.h>
#include <string>
#ifdef __ANDROID__
#include <android/log.h>
#elif defined(__APPLE__)
#include <iostream>
#endif

namespace STDSLog {
typedef enum {
    STDSLOG_NONE = 0,
    STDSLOG_ERROR = 1,
    STDSLOG_WARN = 2,
    STDSLOG_INFO = 3,
    STDSLOG_DEBUG = 4
} STDSLOG_LEVEL;

static STDSLOG_LEVEL LOG_Level = STDSLOG_DEBUG;
#define LOG_TAG "STDSLog"
template<class... T>
void outputConsole(const char *fmt, const T&...t) {

#ifdef __ANDROID__
    __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, fmt, t...);
#elif defined(__APPLE__)
    const auto len = snprintf(nullptr, 0, fmt, t...);
    std::string str;
    str.resize(static_cast<size_t>(len) + 1);
    snprintf(&str.front(), len + 1, fmt, t...);
    str.resize(static_cast<size_t>(len));
    printf("\n%s\n", str.c_str());
#endif
}

template<class... T>
void DebugLog(const char *fmt, const T&...t) {
    if (LOG_Level < STDSLOG_DEBUG) {
        return;
    }
    outputConsole(fmt, t...);
}
template<class... T>
void ErrorLog(const char *fmt, const T&...t) {
    if (LOG_Level < STDSLOG_ERROR) {
        return;
    }
    outputConsole(fmt, t...);
}

template<class... T>
void InfoLog(const char *fmt, const T&...t) {
    if (LOG_Level < STDSLOG_INFO) {
        return;
    }
    outputConsole(fmt, t...);
}

template<class... T>
void WarnLog(const char *fmt, const T&...t) {
    if (LOG_Level < STDSLOG_WARN) {
        return;
    }
    outputConsole(fmt, t...);
}
}

#define  LOG_DEBUG(...) STDSLog::DebugLog(__VA_ARGS__);
#define  LOG_INFO(...) STDSLog::InfoLog(__VA_ARGS__);
#define  LOG_ERROR(...) STDSLog::ErrorLog(__VA_ARGS__);
#define  LOG_WARN(...) STDSLog::WarnLog(__VA_ARGS__);


#endif /* STDSLog_h */
